Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
is-generator-function
Advanced tools
The is-generator-function package is a utility that allows you to check if a given function is a generator function. This can be particularly useful when working with code that dynamically generates functions or when integrating with libraries that may use generator functions for asynchronous control flow.
Check if a function is a generator function
This feature allows you to distinguish between regular JavaScript functions and generator functions. By passing a function to `isGeneratorFunction`, it returns `true` if the function is a generator function and `false` otherwise. This can be useful for dynamic function handling or when working with APIs that may provide generator functions.
const isGeneratorFunction = require('is-generator-function');
function* myGenerator() {}
const regularFunction = function() {};
console.log(isGeneratorFunction(myGenerator)); // true
console.log(isGeneratorFunction(regularFunction)); // false
Similar to is-generator-function, is-generator checks if a given value is a generator object, which is different from checking if a function is a generator function. It's useful for identifying generator objects, but not for identifying generator functions directly.
While is-function is more general and checks if a given value is a function, it does not specifically differentiate between regular functions and generator functions. It's broader in scope compared to is-generator-function, which is specifically designed to identify generator functions.
Is this a native generator function?
var isGeneratorFunction = require('is-generator-function');
assert(!isGeneratorFunction(function () {}));
assert(!isGeneratorFunction(null));
assert(isGeneratorFunction(function* () { yield 42; return Infinity; }));
Simply clone the repo, npm install
, and run npm test
FAQs
Determine if a function is a native generator function.
The npm package is-generator-function receives a total of 19,218,341 weekly downloads. As such, is-generator-function popularity was classified as popular.
We found that is-generator-function demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.